package com.ddwl.order.controller;

import com.ddwl.common.controller.BaseController;
import com.ddwl.common.feign.api.GoodsApi;
import com.ddwl.order.annotation.Erp;
import com.ddwl.order.service.AfterSaleOrderServer;
import com.ddwl.order.service.OrderAddressServer;
import com.ddwl.order.service.OrderInfoServer;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.ItemListApiBo;
import com.ddwl.schema.bo.order.OrderApiBo;
import com.ddwl.schema.bo.order.OrderDeliveryApiBo;
import com.ddwl.schema.bo.order.OrderListApiBo;
import com.ddwl.schema.bo.order.QueryAfterSaleOrderListApiBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.ItemApiVo;
import com.ddwl.schema.vo.goods.SkuVo;
import com.ddwl.schema.vo.order.AfterSaleOrderVo;
import com.ddwl.schema.vo.order.OrderAddrVo;
import com.ddwl.schema.vo.order.OrderDetailsVo;
import com.ddwl.schema.vo.order.OrderInfoListApiVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 订单相关openAPI
 *
 * @author wenbin
 * @Date :2020-08-12
 */
@RestController
@RequestMapping("/ddwlOpenApi")
public class OrderOpenApiController extends BaseController {

    @Resource
    private OrderInfoServer orderInfoServer;
    @Resource
    private OrderAddressServer orderAddresServer;
    @Resource
    private AfterSaleOrderServer afterSaleOrderServer;

    @Erp(name = "查询发货订单列表")
    @PostMapping("/orderlist")
    @ApiOperation("查询发货订单列表")
    public RestVo<PageVo<OrderAddrVo>> getOrderList(@RequestBody PageBo<OrderListApiBo> bo) {
        return RestVo.ok(orderAddresServer.getApiPage(bo));
    }


    @Erp(name = "查询主订单列表")
    @PostMapping("/mainOrderlist")
    @ApiOperation("查询主订单列表")
    public RestVo<PageVo<OrderInfoListApiVo>> getMainOrderList(@RequestBody PageBo<OrderListApiBo> bo) {
        return RestVo.ok(orderInfoServer.getMainApiPage(bo));
    }


    @Erp(name = "获取订单详情")
    @PostMapping("/orderDetail")
    @ApiOperation("获取订单详情接口")
    public RestVo<OrderDetailsVo> detail(@RequestBody PageBo<OrderApiBo> bo) {
        return RestVo.ok(orderInfoServer.getOrderApiDetail(bo.getParam()));
    }

    @Erp(name = "订单发货")
    @PostMapping("/delivery")
    @ApiOperation("订单发货")
    public RestVo delivery(@RequestBody PageBo<OrderDeliveryApiBo> bo) {
        orderInfoServer.orderApiDelivery(bo.getParam());
        return RestVo.ok();
    }

    @Erp(name = "同步库存数量")
    @PostMapping("/updateRealStock")
    @ApiOperation("同步库存数量")
    public RestVo updateRealStock(@RequestBody PageBo<ItemListApiBo> bo) {
        bo.setAsc(false);
        orderInfoServer.updateRealStock(bo);
        return RestVo.ok();
    }


    @Erp(name = "分页查询商品")
    @PostMapping("/itemlist")
    @ApiOperation("分页查询子商品")
    public RestVo<PageVo<SkuVo>> index(@RequestBody PageBo<ItemListApiBo> pageBo) {
        pageBo.setAsc(false);
        return orderInfoServer.index(pageBo);
    }

    @Erp(name = "分页查询主商品")
    @PostMapping("/mainItemlist")
    @ApiOperation("分页查询主商品")
    public RestVo<PageVo<ItemApiVo>> mainItemlist(@RequestBody PageBo<ItemListApiBo> pageBo) {
        pageBo.setAsc(false);
        return orderInfoServer.mainiItemlist(pageBo);
    }

    @Erp(name = "分页查询售后单据")
    @PostMapping("/afterSaleList")
    @ApiOperation("分页查询售后单据")
    public RestVo<PageVo<AfterSaleOrderVo>> afterSaleList(@RequestBody PageBo<QueryAfterSaleOrderListApiBo> pageBo) {
        return RestVo.ok(afterSaleOrderServer.getApiPage(pageBo));
    }

}
